package com.hzw.saas.web.admin.user.controller;

import javax.annotation.Resource;

import com.hzw.saas.api.user.IUserAccountService;
import com.hzw.saas.api.user.query.UserAccountGetQuery;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSort;
import lombok.RequiredArgsConstructor;

/**
 * <p>
 * saas用户管理控制器
 * </p>
 *
 * @author sonam
 * @since 2021/2/25 13:11
 */
//@ApiIgnore
@Api(tags = "用户参数校验")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserAccountController {

    @Resource(name = "userAccountServiceImpl")
    private IUserAccountService userAccountService;

    @GetMapping("/exists/username/{username}")
    @ApiOperation(value = "验证用户名", notes = "验证用户名是否重复")
    @ApiImplicitParam(name = "username", value = "用户名", required = true, dataType = "String")
    @ApiOperationSort(2)
    public ResponseEntity<Boolean> existsUsername(@PathVariable String username) {
        boolean exists = userAccountService.existAccount(new UserAccountGetQuery().setUserName(username));
        return ResponseEntity.ok(exists);
    }

    @GetMapping("/exists/phone/{phone}")
    @ApiOperation(value = "验证手机号", notes = "验证手机号是否重复")
    @ApiImplicitParam(name = "phone", value = "手机号", required = true, dataType = "String")
    @ApiOperationSort(3)
    public ResponseEntity<Boolean> existsPhoneNo(@PathVariable String phone) {
        boolean exists = userAccountService.existAccount(new UserAccountGetQuery().setPhoneNo(phone));
        return ResponseEntity.ok(exists);
    }

    @GetMapping("/exists/email/{email}")
    @ApiOperation(value = "验证邮箱", notes = "验证邮箱是否重复")
    @ApiImplicitParam(name = "email", value = "邮箱", required = true, dataType = "String")
    @ApiOperationSort(4)
    public ResponseEntity<Boolean> existsEmail(@PathVariable String email) {
        boolean exists = userAccountService.existAccount(new UserAccountGetQuery().setEmail(email));
        return ResponseEntity.ok(exists);
    }

}
